﻿#include <conio.h>
#include <stdlib.h>
#include "Menu.h"
#include "Exception.h"

Menu::Menu(string q, list<string> qL) : question(q), optionList(qL) 
{
}

Menu::MenuSelection Menu::show()
{
	cout << endl;
	cout << question << endl;
	int line_number = 1;
	for (auto line = optionList.begin(); line != optionList.end(); line++, line_number++)
	{
		cout << line_number << ": " << *line << endl;
	}
	int select = -1;
	cout << "请输入你的选择：";
	for (; select > optionList.size() + '0' || select <= '0';)
	{
		select = _getch();
		if (select == 'q' || select == 'Q')
		{
			// 返回上一级
			throw GobackException();
		}
	}
	cout << (char)select << endl
		 << endl;
	return select - '0';
}

Menu Menu::mainMenu("你要进入的子系统", {"管理系统", "借阅系统"});

Menu Menu::adminMenu("你要进入的管理子系统", {"读者管理", "图书管理","借阅管理（未实现）"});

Menu Menu::borrowMenu("你要进行的操作", {"借书", "还书", "查询"});

Menu Menu::borrowQueryMenu("查询依据", {"根据读者查询", "根据图书查询"});

Menu Menu::adminReaderMenu("要进行的操作", {"注册读者", "查询读者", "删除读者"});

Menu Menu::adminBookMenu("要进行的操作", {"图书入库", "查看图书列表（查看全部）", "图书销毁"});
